/*
    Copyright (C) 2013 maik.jablonski@jease.org

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package jfix.zk;

import java.util.Date;

import org.zkoss.zul.Hbox;

public class Eventfield extends Hbox {

	private Datefield date = new Datefield();
	private Timebox start = new Timebox();
	private Timebox end = new Timebox();

	public Eventfield() {
		appendChild(date);
		appendChild(start);
		appendChild(new Label("-"));
		appendChild(end);
	}

	public void setDate(Date newDate) {
		date.setDate(newDate);
	}

	public Date getDate() {
		return date.getDate();
	}

	public void setStartTime(String time) {
		start.setText(time);
	}

	public void setEndTime(String time) {
		end.setText(time);
	}

	public String getStartTime() {
		return start.getText();
	}

	public String getEndTime() {
		return end.getText();
	}

	public boolean isEmpty() {
		return date.isEmpty() || start.isEmpty() || end.isEmpty();
	}
	
	public int getStartTimeInMintues() {				
		return getMintues(start.getText());		
	}

	public int getEndTimeInMintues() {				
		return getMintues(end.getText());		
	}

	private int getMintues(String text) {		
		String[] fields = text.split(":");
		int minutes = Integer.parseInt(fields[0]) * 60;
		if (fields.length == 2) {
			minutes += Integer.parseInt(fields[1]);
		}
		return minutes;		
	}
	
}
